home *** CD-ROM | disk | FTP | other *** search
- /* contour2 - subsidiary routines for contour drawing
-
- None of these routines refers to a global variable
-
- */
-
- #include <stdio.h>
- #include <math.h>
-
- #define maximum(a,b) ((a)>(b)?(a):(b))
-
- int mygets(buf,size,f,fout) char *buf; int size; FILE f,fout;
- { char *t;
- while(1)
- {if(fgets(buf,size,f)==0) {return 0;}
- t=buf;
- while(*t && isspace(*t)) t++;
- if(*t == 0) continue; /* skip blank lines */
- buf[strlen(buf)-1]=0; /* zero out the line feed */
- if(buf[0]==';')
- {printf("%s\n",buf); continue;
- fprintf(fout,"%s\n",buf); continue;
- } /* skip comment */
- return 1;
- }
- }
-
- get_double(argc,argv,permitted,a,b,c)
- int argc,permitted; char **argv; double *a,*b,*c;
- { int i=1;
- if((permitted--)>0 && (argc>i) && numeric(argv[i])) *a=atof(argv[i++]);
- if((permitted--)>0 && (argc>i) && numeric(argv[i])) *b=atof(argv[i++]);
- if((permitted--)>0 && (argc>i) && numeric(argv[i])) *c=atof(argv[i++]);
- return i;
- }
-
- int streq(a,b) char *a,*b;
- { while(*a)
- {if(*a!=*b)return 0;
- a++; b++;
- }
- return 1;
- }
-
- gripe_arg(s) char *s;
- { fprintf(stderr,"argument missing for switch %s",s);
- help();
- }
-
- gripe(argv) char **argv;
- { fprintf(stderr,*argv); fprintf(stderr," isn\'t a legal argument \n\n");
- help();
- }
-
- numeric(s) char *s;
- { char c;
- while(c=*s++)
- {if((c<='9' && c>='0') || c=='+' || c=='-' || c=='.') continue;
- return 0;
- }
- return 1;
- }
-
-
- static double decide[3]= {1.414, 3.162, 7.071};
- static int mtic[4]= {1, 2, 5, 10};
-
- scale_one (amin,amax,bmin,bmax,lab_requested,nlab,kind)
- double amin,amax,*bmin,*bmax; int lab_requested, *nlab, kind;
- { double tens, top, bottom, fraction, d;
- int i,j;
-
- if(!kind) /* linear scale */
- {if(amax<=amin) amax=amin+1.;
- fraction=(amax-amin)/maximum(lab_requested-1,1);
- #ifdef xxx
- printf("\nscale_one: fraction=%f",fraction);
- #endif
- tens=pow(10.,floor(log10(fraction)));
- fraction/=tens;
- for (j=0; j<=2; j++) if(fraction<decide[j]) break;
- d=mtic[j]*tens; /* data increment between labels */
- bottom=floor(amin/d); *bmin=bottom*d;
- top=ceil(amax/d); *bmax=top*d;
- *nlab=(int)(top-bottom+.25); /* # labels */
- #ifdef xxx
- printf("(-->%f) ?= d=%f, tens=%f \n",fraction,d,tens);
- printf(" bottom=%f, top=%f, j=%d \n",
- bottom,top,j);
- printf("labels range from bmin=%f to bmax=%f in nlab=%d steps \n",
- *bmin, *bmax, *nlab);
- #endif
- }
- else /* log scale */
- {*bmin=floor(amin+.001); *bmax=ceil(amax-.001);
- *nlab= *bmax - *bmin + .1;
- #ifdef xxx
- printf("\n scale_one: *bmin=%f *bmax=%f *nlab=%d kind=%d \n",
- *bmin, *bmax, *nlab, kind);
- #endif
- }
- }
-
- /* return scale factor and format for printing nlx labels from x1 to x2 */
- double adjust(fmt,x1,x2,nlx) char *fmt; double x1,x2; int nlx;
- { double large,a1,a2,adj=1.;
- int exponent=0,after; /* "after" is # digits needed after decimal */
- a1=fabs(x1);
- a2=fabs(x2);
- large=(a1>a2)?a1:a2;
- if(large<.01)
- while(large*adj < 1.) {adj *= 1000.; exponent -= 3;}
- while(large*adj > 1000.) {adj /= 1000.; exponent += 3;}
- after=ceil(-log10((x2*adj-x1*adj)/nlx));
- if(after<0) after=0;
- if(exponent)
- {sprintf(fmt," %%%d.%dfe%d",after,after,exponent);
- }
- else
- {sprintf(fmt," %%%d.%df",after,after);
- }
- return (adj);
- }
-
-
-